package ltd.newson.easy;

import java.util.List;
import java.util.LinkedList;

public class EASY_590_N叉树的后序遍历 {

    class Node {
        public int val;
        public List<Node> children;

        public Node() {}

        public Node(int _val) {
            val = _val;
        }

        public Node(int _val, List<Node> _children) {
            val = _val;
            children = _children;
        }
    }

    List<Integer> list = new LinkedList<>();

    public List<Integer> postorder(Node root) {
        if (root != null) {
            int size = root.children.size();
            for (int i = 0; i < size; i++) {
                postorder(root.children.get(i));
            }
            list.add(root.val);
        }
        return list;
    }

    public List<Integer> postorder1(Node root) {
        if (root == null) {
            return list;
        }
        for (Node node : root.children) {
            postorder(node);
        }
        list.add(root.val);
        return list;
    }

}


